package vistas;


import javax.jms.JMSException;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.Color;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JLabel;

import activeQM.productorQMColaServidor;
import contenedorSpring.Contenedor;
import Iview.IFormEscritorioEstudiante;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class FormEscritorioEstudiante extends JFrame implements
		IFormEscritorioEstudiante {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;

	/**
	 * Create the frame.
	 */
	public FormEscritorioEstudiante() {
		setResizable(false);
		setExtendedState(JFrame.MAXIMIZED_HORIZ);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 312, 84);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		JButton btnNewButton = new JButton("Compartir pantalla");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				productorQMColaServidor qm = (productorQMColaServidor) Contenedor.getSingleton().getApplicationContext().getBean("producerCompartirPantalla");
				try {
					qm.sendMessages(InetAddress.getLocalHost().getHostAddress());
				} catch (UnknownHostException | JMSException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		JLabel lbDescripcion = new JLabel("Descripcion");
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_contentPane
						.createSequentialGroup()
						.addContainerGap()
						.addComponent(btnNewButton)
						.addGap(18)
						.addComponent(lbDescripcion, GroupLayout.DEFAULT_SIZE,
								193, Short.MAX_VALUE).addContainerGap()));
		gl_contentPane
				.setVerticalGroup(gl_contentPane
						.createParallelGroup(Alignment.LEADING)
						.addGroup(
								gl_contentPane
										.createSequentialGroup()
										.addGroup(
												gl_contentPane
														.createParallelGroup(
																Alignment.BASELINE)
														.addComponent(
																lbDescripcion,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE)
														.addComponent(
																btnNewButton,
																GroupLayout.PREFERRED_SIZE,
																47,
																GroupLayout.PREFERRED_SIZE))
										.addContainerGap(11, Short.MAX_VALUE)));
		contentPane.setLayout(gl_contentPane);
	}

	@Override
	public void mostrarMensaje(int tipo, String mensaje) {
		switch (tipo) {
		case 1:// mensaje de aceptacion de compartir pantalla
			JOptionPane.showMessageDialog(null, mensaje, "Aceptación",
					JOptionPane.INFORMATION_MESSAGE);
			break;
		case 2:// mensaje de negacion de compartir pantalla
			JOptionPane.showMessageDialog(null, mensaje, "Negación",
					JOptionPane.CANCEL_OPTION);
			break;
		}
		
	}
}
